﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using caedisi.Web.DataModel;
using caedisi.Models;

namespace caedisi.Views
{
    /// <summary>
    /// The neighbourhood definition class
    /// </summary>
    public partial class NeighbourhoodDefinition : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="NeighbourhoodDefinition"/> class.
        /// </summary>
        public NeighbourhoodDefinition()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Handles the Click event of the buttonAddNewNeighbourhoodDefinition control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void buttonAddNewNeighbourhoodDefinition_Click(object sender, RoutedEventArgs e)
        {
            NeighbourhoodType newNeighbourhoodType = new NeighbourhoodType()
            {
                NeighbourhoodTypeId = -1
            };

            NeighbourhoodDefinitionEdit neighbourhoodDefinitionEditWindow = new NeighbourhoodDefinitionEdit(newNeighbourhoodType);
            neighbourhoodDefinitionEditWindow.Show();
            neighbourhoodDefinitionEditWindow.Closed += new EventHandler(
                (s,ev) =>
                {
                    if (neighbourhoodDefinitionEditWindow.DialogResult == true)
                    {
                        Globals.Instance.Lovs.NeighbourhoodTypes.Add(neighbourhoodDefinitionEditWindow.CurrentEntity);
                    }                
                }
                );
        }        
    }
}
